package com.springboot.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.springboot.po.Coupon;
import com.springboot.po.UserCoupon;

@Mapper
public interface UserCouponMapper {
	@Select("select typeId from usercoupon where userId = #{userId}")
	public List<Integer> listUserCoupon(String userId);
	
	
	@Select("select quantity from usercoupon where userId = #{userId} and typeId = #{typeId}")
	public Integer getCouponQuantity(String userId , Integer typeId);
	
	@Select("select * from usercoupon where userId = #{userId} and typeId = #{typeId}")
	public UserCoupon getUerCoupon(String userId , Integer typeId);
	
	//减1
	@Update("update usercoupon set quantity = (quantity-1)  where typeId = #{typeId} and userId = #{userId}")
	public Integer updateUserCoupon(String userId , Integer typeId);
	
	@Delete("delete from usercoupon where userId = #{userId} and typeId = #{typeId}")
	public Integer deleteUserCoupon(String userId , Integer typeId);
	
	@Insert("insert into usercoupon(userId,typeId,quantity) values(#{userId},#{typeId},1)")
	public Integer insertUserCoupon(String userId,Integer typeId);
	
	@Update("update usercoupon set quantity = (quantity+1)  where typeId = #{typeId} and userId = #{userId}")
	public Integer addUserCoupon(String userId,Integer typeId);
	
	@Select("select * from usercoupon where userId = #{userId} order by typeId")
	public List<UserCoupon> listUserCouponAll(String userId);
}
